package main

import (
	"context"
	"fmt"
	"time"
)

func doSomething(ctx context.Context) {
	for {
		select {
		case <-ctx.Done():
			fmt.Println("done")
		case <-time.After(5 * time.Second):
			fmt.Println("finish ...")
		}
	}

}

func main() {
	ctx := context.Background()
	ctx1, _ := context.WithTimeout(ctx, 2*time.Second)
	doSomething(ctx1)
	//go func() {
	//	time.Sleep(5 * time.Second)
	//	cancelFunc()
	//}()
}
